package cn.zsb.PolymorphicDemo;

public class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void keepPet(Animal animal, String something) {
        if (animal instanceof Dog d) {
            System.out.println(age + "岁的" + name + "养了只" + animal.getColor()
                    + "颜色的" + animal.getAge() + "岁的狗狗");
            d.eat(something);
        }else if (animal instanceof Cat c) {
            System.out.println(age + "岁的" + name + "养了只" + animal.getColor()
                    + "颜色的" + animal.getAge() + "岁的小猫老弟");
            c.eat(something);
        }else {
            System.out.println("没有这种动物·");
        }
    }

    /*//饲养狗
    public void keepPet(Dog dog, String something) {
        System.out.println(age + "岁的" + name + "养了只" + dog.getColor()
        + "颜色的" + dog.getAge() + "岁的狗狗");
        dog.eat(something);
    }

    //饲养猫
    public void keepPet(Cat cat, String something) {
        System.out.println(age + "岁的" + name + "养了只" + cat.getColor()
                + "颜色的" + cat.getAge() + "岁的小猫");
        cat.eat(something);
    }*/
}
